var t,
  a =
    (t = require("../../location-aoa/LocationBehavior")) && t.__esModule
      ? t
      : { default: t };
var i = {
  singleIcon: {
    markerId: 90009,
    name: "单一图标",
    iconPath:
      "https://industry.map.qq.com/cloud/file/2023/08/16/location_icon_full_v2@3x.png",
    width: 48,
    height: 48,
    anchor: { x: 0.5, y: 0.5 },
  },
  multipleIcon: {
    name: "复合图标",
    arrowMarkerId: 90009,
    arrowIconPath:
      "https://industry.map.qq.com/cloud/file/2023/08/09/location_icon_arrow_full@3x.png",
    centerMarkerId: 90010,
    centerIconPath:
      "https://industry.map.qq.com/cloud/file/2023/08/09/location_icon_center_full@3x.png",
    width: 56,
    height: 56,
    anchor: { x: 0.5, y: 0.5 },
  },
};
Page({
  behaviors: [a.default],
  data: {
    isReady: !1,
    isStarted: !1,
    position: void 0,
    heading: 0,
    latitude: 31.002384,
    longitude: 104.220417,
    scale: 18,
    setting: { skew: 0, rotate: 0 },
    markers: [],
    polyline: [],
    levelPick: !0,
    indoor: !0,
    indoorInfo: {},
    content: "",
    showlocation: !0,
    rotation: 0,
    buildingId: -1,
    floorList: [],
    floorIndex: -1,
  },
  onLoad: function () {
    this.mapCtx = wx.createMapContext("myMap");
  },
  handleFloorChange: function (t) {
    var a = t.detail.buildingId,
      i = t.detail.floor;
    this.mapCtx.setIndoorFloor &&
      this.mapCtx.setIndoorFloor({ buildingId: a, floorName: i });
  },
  onLocationChange: function (t) {
    var a = this.data.markers,
      i = this.data.markers.find(function (t) {
        return 90009 === t.id;
      });
    if (i)
      (i.latitude = t.latitude),
        (i.longitude = t.longitude),
        this.translateNavMarker({
          latitude: t.latitude,
          longitude: t.longitude,
          duration: 200,
          rotate: this.rotateDirection,
        });
    else {
      var o = this.createLocationMarkers(
        "single",
        t.latitude,
        t.longitude,
        this.rotateDirection,
      );
      this.setData({
        latitude: t.latitude,
        longitude: t.longitude,
        markers: a.concat(o),
      });
    }
    (this.lastestLocation = t),
      this.setData({
        position: ""
          .concat(t.latitude, ",")
          .concat(t.longitude, ", ")
          .concat(t.floorName),
      }),
      t.buildingId === this.buildingId &&
        t.floorName !== this.floorName &&
        (this.mapCtx.setIndoorFloor({
          buildingId: t.buildingId,
          floorName: t.floorName,
        }),
        console.log("====setIndoorFloor:", t.floorName, t.floorName));
  },
  onCompassChange: function (t) {
    var a = this.getMapRotate().rotate + t.direction;
    (this.rotateDirection = a % 360),
      this.setData({ rotation: this.rotateDirection, accuracy: t.accuracy });
  },
  onIndoorchange: function (t) {
    var a = t.info && t.info.floorIndex,
      i = (t.info && t.info.floorList) || [],
      o = t.info && t.info.buildingId;
    (this.floorName = i && i[a]),
      (this.buildingId = o),
      (this.buildingName = t.info && t.info.buildingName),
      this.setData({ buildingId: o, floorList: i, floorIndex: a });
  },
  onRegionchange: function (t) {
    if ("end" === t.type) {
      var a = t.detail && t.detail.rotate,
        i = t.detail && t.detail.skew;
      null != a && null != a && (this.data.setting.rotate = a),
        null != i && null != i && (this.data.setting.skew = i);
    }
  },
  getMapRotate: function () {
    return { rotate: this.data.setting.rotate, skew: this.data.setting.skew };
  },
  createLocationMarkers: function (t, a, o) {
    var e = [];
    if ("single" === t) {
      var n = i.singleIcon;
      e.push({
        id: n.markerId,
        latitude: a,
        longitude: o,
        iconPath: n.iconPath,
        width: n.width,
        height: n.height,
        _name: "我的位置",
        anchor: n.anchor,
        rotate: 0,
        isLocationIcon: !0,
      });
    }
    if ("multiple" === t) {
      var r = i.multipleIcon;
      e.push(
        {
          id: r.arrowMarkerId,
          latitude: a,
          longitude: o,
          iconPath: r.arrowIconPath,
          width: r.width,
          height: r.height,
          _name: "我的位置",
          anchor: r.anchor,
          rotate: this.rotateDirection || 0,
          isLocationIcon: !0,
        },
        {
          id: r.centerMarkerId,
          latitude: a,
          longitude: o,
          iconPath: r.centerIconPath,
          width: r.width,
          height: r.height,
          _name: "个性化中心点",
          anchor: r.anchor,
          isLocationIcon: !0,
        },
      );
    }
    return e;
  },
  updateLocationMarker: function (t, a, o) {
    var e = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 0;
    if ("single" === t) {
      var n = i.singleIcon,
        r = this.data.markers.find(function (t) {
          return t.id === n.markerId;
        });
      r && ((r.latitude = a), (r.longitude = o), (r.rotate = e));
    }
    if ("multiple" === t) {
      var l = i.multipleIcon,
        d = this.data.markers.filter(function (t) {
          return t.id === l.arrowMarkerId || t.id === l.centerMarkerId;
        });
      d.forEach(function (t) {
        (t.latitude = a),
          (t.longitude = o),
          t.id === l.arrowMarkerId && (t.rotate = e);
      });
    }
    this.setData({ markers: this.data.markers });
  },
  translateNavMarker: function (t, a) {
    var i = this;
    if (t && !this.isTranslateNavMarker) {
      var o = {
        markerId: 90009,
        duration: t.duration || 200,
        autoRotate: !1,
        destination: { longitude: t.longitude, latitude: t.latitude },
        moveWithRotate: !0,
      };
      null !== t.rotate && void 0 !== t.rotate && (o.rotate = t.rotate),
        this.setData({ translateRotation: o.rotate }),
        (this.lastAnimationTime = new Date().getTime()),
        (o.animationEnd = function (t) {
          (i.isTranslateNavMarker = !1), a && a({ status: !0 });
        }),
        (o.fail = function (t) {
          console.log("====fail:", o),
            (i.isTranslateNavMarker = !1),
            a && a({ status: !1 });
        }),
        (o.complete = function (t) {
          i.isTranslateNavMarker = !1;
        }),
        this.mapCtx && this.mapCtx.translateMarker(o);
    }
  },
  onUnload: function () {},
});
